<script>
import popupSelectorMultiple from "@/components/popupPicker/popupSelectorMultiple.vue"
export default {
  name: "collegeTypeSelector",
  components: { popupSelectorMultiple },
  props: {
    is_985: Number,
    is_211: Number,
    syl: Number,
    is_zihuaxian: Number,
		typeSchoolNames: Array,
  },
  methods: {
    open() {
      this.$refs.picker.open(this.currentSelect)
    },
  },
  data() {
    return {
      optionList: [
        {
          value: "is_985",
          label: "985",
        },
        {
          value: "is_211",
          label: "211",
        },
        {
          value: "syl",
          label: "双一流",
        },
        {
          value: "is_zihuaxian",
          label: "自划线",
        },
				{
					value: "高等院校",
					label: "高等院校",
				},
				{
					value: "科研院所",
					label: "科研院所",
				},
      ],
    }
  },
  computed: {
    currentSelect: {
      get() {
        const value = []
        if (this.is_985 === 1) {
          value.push("is_985")
        }
        if (this.is_211 === 1) {
          value.push("is_211")
        }
        if (this.syl === 1) {
          value.push("syl")
        }
        if (this.is_zihuaxian === 1) {
          value.push("is_zihuaxian")
        }
				if (this.typeSchoolNames.includes("高等院校")) {
					value.push("高等院校")
				}
				if (this.typeSchoolNames.includes("科研院所")) {
					value.push("科研院所")
				}
        return value
      },
      set(val) {
        const obj = {
          is_985: 0,
          is_211: 0,
          syl: 0,
          is_zihuaxian: 0,
        }
        val.forEach((item) => {
          obj[item] = 1
        })
        for (let objKey in obj) {
          this.$emit(`update:${objKey}`, obj[objKey])
        }
				const typeSchoolNames = []
				if (val.includes("高等院校")) {
					typeSchoolNames.push("高等院校")
				}
				if (val.includes("科研院所")) {
					typeSchoolNames.push("科研院所")
				}
				this.$emit("update:typeSchoolNames", typeSchoolNames)
      },
    },
  },
}
</script>

<template>
  <popup-selector-multiple
    ref="picker"
    :picker-option-list-props="optionList"
    @confirm="
      (val) => {
        currentSelect = val
        $emit('confirm')
      }
    "
    title="院校特色选择"
  ></popup-selector-multiple>
</template>

<style scoped lang="scss"></style>
